/**************************************** LGE TOOLS *************************************************/
Lge.tools = function(){};

Lge.tools.getMouseObject = function(e){
	var mouse = new Object();
	if(document.all){//IE
		e=event;
		mouse.x = e.clientX + document.body.scrollLeft;
		mouse.y = e.clientY + document.body.scrollTop;
	} 
	else{
		mouse.x = e.pageX; mouse.y = e.pageY;
	}
	return mouse;
};

Lge.tools.hypo = function(x,y){
	return Math.sqrt(Math.pow((x),2)+Math.pow((y),2));
};
	
Lge.tools.vectorRotate = function(v,a){
	x = v.x * Math.cos(a) - v.y * Math.sin(a);
	y = v.x * Math.sin(a) + v.y * Math.cos(a);
	return {x:x,y:y};
};

Lge.tools.vectorSubs = function(v1,v2){
	return {x:v1.x - v2.x,y:v1.y - v2.y};
};
Lge.tools.vectorSums = function(v1,v2){
	return {x:v1.x + v2.x,y:v1.y + v2.y};
};

Lge.tools.isPointInPoly = function(poly, pt){
	var i = 0;var j = 0;
	var c = false;
	for (i = 0, j = poly.length-1; i < poly.length; j = i++) {
		if ((((poly[i].y<=pt.y) && (pt.y<poly[j].y)) ||
		((poly[j].y<=pt.y) && (pt.y<poly[i].y))) &&
		(pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - 

poly[i].y) + poly[i].x))
			c = !c;
		}
	return c;
};

Lge.tools.findAngle = function(o){
	var a = Math.atan( o.y / o.x );
	if(o.x == 0)
		a=Math.PI/2;
	else if( o.x < 0 ){
		a+=Math.PI;
	}else if(a<0)
		a+= Math.PI*2;
	return a;
};

Lge.tools.angleBetween = function(o1,o2){
	var a = Lge.tools.findAngle(o1) - Lge.tools.findAngle(o2);
	if(a<0)
		a*=-1;
	if(a>Math.PI)
		a=Math.PI*2-a;
	return a;
};

Lge.tools.proj = function(o1,o2){
	var c =  Lge.tools.hypo(o1.x,o1.y) * Math.cos(Lge.tools.angleBetween(o1,o2));
	var a = Lge.tools.findAngle(o2);
	var x = c * Math.cos(a);
	var y = c * Math.sin(a);
	return new Lpe.Vector(x,y);
};

Lge.tools.distToLine2=function (lineTangent,linePoint,point){
	var dist = ( (lineTangent.x)*(linePoint.y-point.y)-(linePoint.x-point.x)*(lineTangent.y) )/
	Lge.tools.hypo(lineTangent.x,lineTangent.y) ;
	return dist;
};
